/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package wf3.util;

import java.io.Serializable;
import java.text.FieldPosition;
import java.text.ParsePosition;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import jodd.mail.EmailAttachment;
import jodd.mail.EmailMessage;
import jodd.mail.ReceivedEmail;

/**
 *
 * @author romulogalindo
 */
public class Correo implements Serializable {

    private ReceivedEmail email;
    private String from;
    private List<String> to_s;
    private List<String> cc_s;
    private String subject;
    private String date;
    private List<Adjunto> attach_s = new ArrayList<>();
    private List<Mensaje> msg_s = new ArrayList<>();
    private boolean adjuntos = false;
    private boolean copias = false;

    public Correo(ReceivedEmail email, String path) {
        this.email = email;
        from = this.email.getFrom();
        to_s = arrayTolist(this.email.getTo());
        cc_s = arrayTolist(this.email.getCc());
        if (cc_s.size() > 0) {
            copias = true;
        }
        subject = this.email.getSubject();
        date = new java.text.SimpleDateFormat("dd/MM/YYYY hh:mm").format(this.email.getReceiveDate());

        try {
            if (this.email.getAttachments() != null & this.email.getAttachments().size() > 0) {
                for (EmailAttachment attach : this.email.getAttachments()) {
                    attach_s.add(new Adjunto(attach,path));
                }
                this.adjuntos = true;
            }
        } catch (Exception ep) {
            ep.printStackTrace();
        }

        for (EmailMessage message : this.email.getAllMessages()) {
            msg_s.add(new Mensaje(message));
        }
    }

    public ReceivedEmail getEmail() {
        return email;
    }

    public void setEmail(ReceivedEmail email) {
        this.email = email;
    }

    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public List<String> getTo_s() {
        return to_s;
    }

    public void setTo_s(List<String> to_s) {
        this.to_s = to_s;
    }

    public List<String> getCc_s() {
        return cc_s;
    }

    public void setCc_s(List<String> cc_s) {
        this.cc_s = cc_s;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public List<Adjunto> getAttach_s() {
        return attach_s;
    }

    public void setAttach_s(List<Adjunto> attach_s) {
        this.attach_s = attach_s;
    }

    public List<Mensaje> getMsg_s() {
        return msg_s;
    }

    public void setMsg_s(List<Mensaje> msg_s) {
        this.msg_s = msg_s;
    }

    public boolean isAdjuntos() {
        return adjuntos;
    }

    public void setAdjuntos(boolean adjuntos) {
        this.adjuntos = adjuntos;
    }

    public boolean isCopias() {
        return copias;
    }

    public void setCopias(boolean copias) {
        this.copias = copias;
    }

    public List arrayTolist(String[] ar) {
        List ls = new ArrayList();
        for (String ar1 : ar) {
            ls.add(ar1);
        }
        return ls;
    }

}
